// 时间戳转日期
export const formatDate = (timestamp, format)=> {
    if (!timestamp) {
        return null;
    }
    // 将时间戳转换为日期对象
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hours = date.getHours();
    const minutes = date.getMinutes();
    const seconds = date.getSeconds();

    // 替换需要的时间格式
    format = format.replace("yyyy", year);
    format = format.replace("MM", month < 10 ? "0" + month : month);
    format = format.replace("dd", day < 10 ? "0" + day : day);
    format = format.replace("HH", hours < 10 ? "0" + hours : hours);
    format = format.replace("mm", minutes < 10 ? "0" + minutes : minutes);
    format = format.replace("ss", seconds < 10 ? "0" + seconds : seconds);
    return format;
}

// 日期转时间戳
export const formatTimestamp = (dateStr) => {
    const date = new Date(dateStr);
    return date.getTime();
}